package org.example;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.DelayQueue;
import java.util.function.Consumer;

public class list_Demo2 {
    public static  void main(String[] args) {
        List<String> list=new ArrayList<>();
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");


        //迭代器
        Iterator<String> it=list.iterator();
        while(it.hasNext()) {
            System.out.println(it.next());
        }
        System.out.println("======1");
        //增强for循环
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("======2");
        //匿名内部类方法
        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        System.out.println("======3");
        //lambda表达式
        list.forEach((String s) ->{
                System.out.println(s);
            }
        );
        System.out.println("======4");
        //lambda表达式省略模式
        list.forEach(s-> System.out.println(s));
        System.out.println("======5");
        //普通for循环
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("======6");
        //列表迭代器
        ListIterator<String> it2=list.listIterator();
        while(it2.hasNext()){
            String n=it2.next();
            //添加元素
            //if(n.equals("aaa")){
                it2.add("ddd");
            //}
            System.out.println(n);
        }
        System.out.println(list);
        System.out.println("======7");
    }
}
